home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Threads Support / ThreadManager.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-14  |  1.8 KB  |  65 lines  |  [TEXT/CWIE]

  1. #ifndef __THREADMANAGER__
  2. #define __THREADMANAGER__
  3. #pragma once
  4.  
  5. #include "Module.h"
  6.  
  7. #include <Threads.h>
  8. #include <Gestalt.h>
  9.  
  10. //--------------------------------------------------------------------------------
  11.  
  12. class ThreadManager : public TModule
  13. {
  14.     DeclareClassSingle(ThreadManager, TModule);
  15.  
  16. protected:
  17.     static ThreadManager*    gThreadManager;
  18.     static long                gThreadGestalt;
  19.     static long                gThreadCount;
  20.     static ThreadTaskRef    gTaskRef;
  21.     
  22. public:
  23.     static ThreadManager&    GetThreadManager();
  24.  
  25.     ThreadManager();
  26.     virtual ~ThreadManager();
  27.     virtual bool    Validate();
  28.     virtual void    Initialize(void);
  29.  
  30.     static ThreadID NewThreadID(ThreadStyle             threadStyle,
  31.                                  ThreadEntryProcPtr     threadEntry,
  32.                                  void *                    threadParam,
  33.                                  Size                     stackSize,
  34.                                  ThreadOptions             options,
  35.                                  void **                threadResult);
  36.     static void*    DisposeThreadID(ThreadID             threadToDump);
  37.     static void*    RecycleThreadID(ThreadID             threadToDump);
  38.                                 
  39.     static inline ThreadTaskRef    GetTaskRef()        { return gTaskRef; }
  40.     
  41.     static inline bool        ThreadManagerPresent()    { return TestBit(gThreadGestalt, gestaltThreadMgrPresent);        }
  42.     static inline bool        SpecificMatchSupport()    { return TestBit(gThreadGestalt, gestaltSpecificMatchSupport);    }
  43.     static inline bool        ThreadsLibraryPresent()    { return TestBit(gThreadGestalt, gestaltThreadsLibraryPresent);    }
  44.  
  45. protected:
  46.     static pascal void        ThreadCreatedProc(ThreadID threadCreated);
  47.     static pascal void        ThreadDeletedProc(ThreadID threadDeleted);
  48.     static pascal ThreadID    ThreadScheduleProc(SchedulerInfoRecPtr schedulerInfo);
  49. };
  50.  
  51. //--------------------------------------------------------------------------------
  52.  
  53. #if !qDebug
  54.  
  55. inline ThreadManager& ThreadManager::GetThreadManager()
  56. {
  57.     return *gThreadManager;
  58. }
  59.  
  60. #endif
  61.  
  62. //--------------------------------------------------------------------------------
  63.  
  64. #endif __THREADMANAGER__
  65.